<!-- <template>
  <div>
    <el-card shadow="never" class="dashboard-card">
      <template #header>
        <div class="card-header">
          <el-icon><Document /></el-icon>
          <span>试题试卷管理</span>
        </div>
      </template>
      <el-table :data="exams" style="width: 100%">
        <el-table-column prop="title" label="试卷名称" />
        <el-table-column prop="course" label="所属课程" />
        <el-table-column prop="date" label="创建日期" />
        <el-table-column label="操作" width="180">
          <template #default="scope">
            <el-button type="primary" size="small" @click="editExam(scope.row)">编辑</el-button>
            <el-button type="danger" size="small" @click="deleteExam(scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div><template>
  <div>
    <el-card shadow="never" class="dashboard-card">
      <template #header>
        <div class="card-header">
          <el-icon><Document /></el-icon>
          <span>试题试卷管理</span>
        </div>
      </template>
      <el-table :data="exams" style="width: 100%" :loading="loading">
        <el-table-column prop="title" label="试卷名称" />
        <el-table-column prop="course" label="所属课程" />
        <el-table-column prop="date" label="创建日期" />
        <el-table-column label="操作" width="180">
          <template #default="scope">
            <el-button type="primary" size="small" @click="editExam(scope.row)">编辑</el-button>
            <el-button type="danger" size="small" @click="deleteExam(scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        v-model:current-page="currentPage"
        v-model:page-size="pageSize"
        :total="total"
        @current-change="fetchExams"
        layout="prev, pager, next"
      />
    </el-card>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue';
import { ElMessage } from 'element-plus';
import { fetchExamList, deleteExamById } from '@/services/examService';

const exams = ref([]);
const loading = ref(false);
const currentPage = ref(1);
const pageSize = ref(10);
const total = ref(0);

const fetchExams = async () => {
  loading.value = true;
  try {
    const { data } = await fetchExamList(currentPage.value, pageSize.value);
    exams.value = data.exams;
    total.value = data.total;
  } catch (error) {
    ElMessage.error('加载试卷列表失败');
  } finally {
    loading.value = false;
  }
};

const editExam = (exam) => {
  console.log('编辑试卷:', exam);
  // 跳转到编辑页面或弹出编辑对话框
};

const deleteExam = async (exam) => {
  try {
    await deleteExamById(exam.id);
    ElMessage.success('试卷删除成功');
    fetchExams();
  } catch (error) {
    ElMessage.error('删除试卷失败');
  }
};

onMounted(() => {
  fetchExams();
});
</script>

<style scoped>
.card-header {
  display: flex;
  align-items: center;
  font-weight: bold;
}
.card-header .el-icon {
  margin-right: 8px;
}
</style>
</template>

<script setup>
import { ref } from 'vue';

const exams = ref([
  { id: 1, title: '期中考试', course: '软件工程导论', date: '2023-09-20' },
  { id: 2, title: '期末考试', course: '计算机网络', date: '2023-10-10' },
]);

const editExam = (exam) => {
  console.log('编辑试卷:', exam);
};

const deleteExam = (exam) => {
  console.log('删除试卷:', exam);
};
</script>

<style scoped>
.card-header {
  display: flex;
  align-items: center;
  font-weight: bold;
}
.card-header .el-icon {
  margin-right: 8px;
}
</style> -->